import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';

class PayController extends GetxController {
  // 支付选项
  RxList payList = [
    {
      "id": 1,
      "title": "支付宝支付",
      "checked": true,
      "image": "https://www.itying.com/themes/itying/images/alipay.png"
    },
    {
      "id": 2,
      "title": "微信支付",
      "checked": false,
      "image": "https://www.itying.com/themes/itying/images/weixinpay.png"
    }
  ].obs;

  // 获取支付方式
  var payType = 1;
  @override
  void onInit() {
    // ignore: todo
    // TODO: implement onInit
    super.onInit();
  }

  @override
  void onClose() {
    // ignore: todo
    // TODO: implement onClose
    super.onClose();
  }

  changePayList(index, id) {
    List<Map<String, Object>> tempList = [];
    for (var i = 0; i < payList.length; i++) {
      payList[i]['checked'] = false;
      tempList.add(payList[i]);
    }
    payType = id;
    tempList[index]['checked'] = true;
    payList.value = tempList;
    update();
  }

  // 支付
  pay() {
    if (payType == 1) {
      if (kDebugMode) {
        print('支付宝');
      }
    } else {
      if (kDebugMode) {
        print('微信');
      }
    }
  }
}
